package com.juzi.wopu.query;

import org.apache.commons.lang3.StringUtils;

public class EmployeeQuery extends BaseQuery{
	
	private String username;
	
	private String email;

	private String[] ages = {"0","130"};
	
	private Long deptId;
  
	private String beginAge;
	
	private String endAge;
	
	private String age="0,130";

	public String getBeginAge() {
		return beginAge;
	}

	public void setBeginAge(String beginAge) {
		this.beginAge = beginAge;
	}

	public String getEndAge() {
		return endAge;
	}

	public void setEndAge(String endAge) {
		this.endAge = endAge;
	}
	
	  public String[] getAges() {
		return ages;
	}

	public void setAges(String[] ages) {
		this.ages = ages;
	}

	public String getAge() {
		return age;
	}

	public void setAge(String age) {
		this.age = age;
	}

	public EmployeeQuery() {
			super("Employee");
	}
	  
   @Override
   protected void addWhere() {
	  if(StringUtils.isNotBlank(username)){
		  AddWhere("o.username like ?","%"+username+"%");
	  }
	  
	  if(StringUtils.isNotBlank(email)){
		  AddWhere("o.email like ?","%"+email+"%");
	  }
	  
	  if(deptId !=null && deptId != -1L){
		  AddWhere("o.department.id=?", deptId);
	  }
	  String[] strings=age.split(",");
	  beginAge=strings[0];
	  endAge=strings[1];
	  AddWhere("o.age>=? and o.age<=?",Integer.parseInt(beginAge),Integer.parseInt(endAge));
	}
	  
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public Long getDeptId() {
		return deptId;
	}
	public void setDeptId(Long deptId) {
		this.deptId = deptId;
	}
}
